package avicit.im.lantop.basic.archiveRecommendFolder.service.api;


import avicit.im.common.CommonTreeNode;
import avicit.im.lantop.basic.archiveRecommendFolder.domain.ArchiveFolder;
import avicit.platform6.core.rest.msg.ResponseMsg;
import avicit.platform6.core.restclient.RestClient;
import avicit.platform6.core.restclient.RestClientUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class ArchiveRecommendFolderServiceApi {


    /**
     * 服务编码
     */
    private static final String SERVICE_CODE = "filebasicmanager";

    private static final String BASE_PATH = "/api/avicit/im/lantop/basic/archiveRecommendFolder/rest/ArchiveRecommendFolderRest";

    @Autowired
    private RestClient restClient;


    /**
     * 获取推荐文件夹表格数据
     * @param orgId
     * @param sysId
     * @param page
     * @param rows
     * @return
     */
    public Map<String, Object> getRecommendFolderDatagrid(String orgId, String sysId, Integer page, Integer rows) {
        String url = BASE_PATH + "/getRecommendFolderDatagrid";
        Map<String,Object> map = new HashMap<>();
        map.put("orgId",orgId);
        map.put("sysId",sysId);
        map.put("page",page);
        map.put("rows",rows);
        ResponseMsg<Map<String, Object>> responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<Map<String, Object>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     * 添加推荐文件夹
     * @param folder
     * @return
     */
    public Integer saveRecommendFolder(ArchiveFolder folder) {
        String url = BASE_PATH + "/saveRecommendFolder";
        Map<String,Object> map = new HashMap<>();
        map.put("folder",folder);
        ResponseMsg<Integer> responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<Integer>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     * 删除推荐文件夹
     * @param folderIds
     */
    public void deleteRecommendFolder(String folderIds) {
        String url = BASE_PATH + "/deleteRecommendFolder";
        Map<String,Object> map = new HashMap<>();
        map.put("folderIds",folderIds);
        ResponseMsg<Integer> responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<Integer>>() {
        });
    }

    /**
     *
     * @param orgId
     * @return
     */
    public List<ArchiveFolder> getArchiveFolderByOrgId(String orgId) {
        String url = BASE_PATH + "/saveRecommendFolder";
        Map<String,Object> map = new HashMap<>();
        map.put("folder",folder);
        ResponseMsg<Integer> responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<Integer>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }
}
